

import lejos.nxt.*;


public class ClapControl {

	public static int CLAP_THRESHOLD = 60;
	
	public static void main (String[] args) throws Exception {
		
		// Instantiating Sensor ports:
		SoundSensor soundsensor = new SoundSensor(SensorPort.S1, true);

		while (true)
		{
			if (Button.ESCAPE.isPressed()) {
				break;
			}

			System.out.println(soundsensor.readValue());
			
			if (soundsensor.readValue() > CLAP_THRESHOLD)
			{
				Thread.sleep(500);
				if (Motor.A.isMoving())
				{
					Motor.A.stop();
					Motor.C.stop();
				} else {
					Motor.A.forward();
					Motor.C.forward();
				}
			}			
		}
	}
}
